"""
ProjectName:qq_tools_bot 
FileName:message.py 
IdeaName:PyCharm 
UserName:zhao
UserMail:2909552840@qq.com
UserHomepage:https://www.zywi.cn
CreationTime:2024/10/30 上午11:56  
"""
from enum import Enum
from typing import Optional, List

from pydantic import BaseModel

from models.event_type import AllReport


class MessageType(Enum):
    """
    消息类型
    """
    PRIVATE = "private"  # 私聊消息
    GROUP = "group"  # 群消息


class MessageSubType(Enum):
    """
    消息子类型
    """
    FRIEND = "friend"  # 好友
    NORMAL = "normal"  # 群聊
    ANONYMOUS = "anonymous"  # 匿名
    GROUP_SELF = "group_self"  # 群中自身发送
    GROUP = "group"  # 群临时会话
    NOTICE = "notice"  # 系统提示


class PostMessageTempSource(Enum):
    """
    临时会话来源
    """
    GROUP_CHAT = 0  # 群聊
    QQ_CONSULTATION = 1  # QQ咨询
    FIND = 2  # 查找
    QQ_MOVIE = 3  # QQ电影
    HOT_CHAT = 4  # 热聊
    VALIDATION_MESSAGE = 6  # 验证消息
    MULTI_PERSON_CHAT = 7  # 多人聊天
    DATE = 8  # 约会
    CONTACT_LIST = 9  # 通讯录


class Sex(Enum):
    """
    性别
    """
    # 男性
    MALE = 'male'
    # 女性
    FEMALE = 'female'
    # 未知
    UNKNOWN = 'unknown'


class Role(Enum):
    """
    角色
    """
    # 群主
    OWNER = 'owner'
    # 管理员
    ADMIN = 'admin'
    # 群成员
    MEMBER = 'member'


class Sender(BaseModel):
    """
    基本发送者信息
    """
    # 发送者 QQ 号
    user_id: Optional[int] = 0
    # 发送者昵称
    nickname: Optional[str] = ''
    # 性别, male 或 female 或 unknown
    sex: Optional[Sex] = Sex.UNKNOWN
    # 年龄
    age: Optional[int] = 0

    # 临时群消息来源群号
    group_id: Optional[int] = 0

    # 群名片／备注
    card: Optional[str] = ''
    # 地区
    area: Optional[str] = ''
    # 成员等级
    level: Optional[str] = ''
    # 角色, owner 或 admin 或 member
    role: Optional[Role] = Role.MEMBER
    # 专属头衔
    title: Optional[str] = ''


class MsType(Enum):
    """
    消息类型
    """
    # 文本
    TEXT = "text"
    # 图片
    IMAGE = "image"
    # @
    AT = "at"
    # 回复
    REPLY = "reply"
    # 系统表情
    FACE = "face"
    # 语音消息
    RECORD = "record"
    # 视频消息
    VIDEO = "video"
    # 超级表情 骰子
    DICE = "dice"
    # 超级表情 猜拳
    RPS = "rps"
    # 音乐卡片
    MUSIC = "music"


class MsData(BaseModel):
    """
    消息数据
    """
    # 配合 @ 使用
    qq: Optional[int] = 0
    # 配合 回复 使用
    id: Optional[int] = 0
    # 文本内容
    text: Optional[str] = ''
    # 图片文件 ID
    file: Optional[str] = ''
    # 图片类型
    sub_type: Optional[int] = 0
    # 图片 URL
    url: Optional[str] = ''
    # 图片大小
    file_size: Optional[str] = ''


class Message(BaseModel):
    """
    消息
    """

    # 消息类型
    type: Optional[MsType] = None
    # 文本数据
    data: Optional[MsData] = None


class Anonymous(BaseModel):
    """
    匿名用户信息
    """
    # 匿名用户
    id: Optional[int] = 0
    # 匿名用户名称
    name: Optional[str] = ''
    # 匿名用户flag
    flag: Optional[str] = ''


class MessageReport(AllReport):
    """
    消息上报类型
    """
    # 消息类型
    message_type: Optional[MessageType] = None
    # 消息子类型
    sub_type: Optional[MessageSubType] = None
    # 临时会话来源
    message_id: int
    # 消息 ID
    user_id: int
    # 发送者 QQ 号
    message: Optional[List[Message]] = []
    # CQ 码格式的消息
    raw_message: Optional[str]
    # 字体
    font: Optional[int]
    # 发送者信息
    sender: Optional[Sender] = None
    # 接受QQ
    target_id: Optional[int] = 0
    # 群号
    group_id: Optional[int] = 0
    # 匿名的标识
    anonymous: Optional[Anonymous] = None
